//======================================================================
// Header file
//
// Written for the book Programming Windows CE
// Copyright (C) 2007 Douglas Boling
//======================================================================
// Returns number of elements
#define dim(x) (sizeof(x) / sizeof(x[0]))

// Windows CE Specific defines
#define LPCMDLINE LPWSTR

//----------------------------------------------------------------------
// Generic defines and data types
//
struct decodeUINT {                            // Structure associates
    UINT Code;                                 // messages
                                               // with a function.
    LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};
struct decodeCMD {                             // Structure associates
    UINT Code;                                 // menu IDs with a
    LRESULT (*Fxn)(HWND, WORD, HWND, WORD);    // function.
};

//----------------------------------------------------------------------
// Defines used by application

typedef struct {
	HANDLE hFile;
	int nDevice;
	TCHAR szName[MAX_PATH];
} SENDTHSTRUCT, *PSENDTHSTRUCT;

#define  ID_ICON             1

#define  IDD_INTEXT          10                // Control IDs
#define  IDD_SENDFILE        11
#define  IDD_SCAN            12
#define  IDD_DEVICES         13

// Error codes used by transfer protocol
#define BAD_TEXTLEN          -1
#define BAD_SOCKET           -2

#define MYMSG_ENABLESEND     (WM_USER+1000)
#define MYMSG_PRINTF         (WM_USER+1001)
#define MYMSG_NEWDEV         (WM_USER+1002)

// Error codes used by transfer protocol
#define GOOD_XFER        0
#define BAD_FILEOPEN     -1
#define BAD_FILEMEM      -2
#define BAD_FILEREAD     -3
#define BAD_FILEWRITE    -3
#define BAD_SOCKETRECV   -5
#define BAD_FILESIZE     -6
#define BAD_MEMORY       -7

#define BLKSIZE          8192                  // Transfer block size
#define BUFFSIZE         8192                  // Buff size (>=BLKSIZE)

//----------------------------------------------------------------------
// Function prototypes
//
HWND InitInstance (HINSTANCE, LPCMDLINE, int);
int TermInstance (HINSTANCE, int);
void Add2List (HWND hWnd, LPTSTR lpszFormat, ...);

// Window procedures
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

// Message handlers
LRESULT DoCreateMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoSizeMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCharMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoPocketPCShell (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDestroyMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoEnableSendMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoPrintfNotifyMain (HWND, UINT, WPARAM, LPARAM);
LRESULT DoAddDeviceMain (HWND, UINT, WPARAM, LPARAM);

// Command functions
LPARAM DoMainCommandSend (HWND, WORD, HWND, WORD);
LPARAM DoMainCommandExit (HWND, WORD, HWND, WORD);
LPARAM DoMainCommandScan (HWND, WORD, HWND, WORD);

// Thread functions
DWORD WINAPI SearchThread (PVOID pArg);
DWORD WINAPI ServerThread (PVOID pArg);
DWORD WINAPI ReceiveThread (PVOID pArg);
DWORD WINAPI SendFileThread (PVOID pArg);
